package com.alvin.demo.controller;

import com.alvin.demo.entity.JobBean;
import com.alvin.demo.job.MyJob;
import com.alvin.demo.utils.JobUtils;
import org.quartz.Scheduler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("job")
public class TestController {

    @Autowired
    private Scheduler scheduler ;

    @GetMapping("create")
    public String createJob(){
        JobBean jobBean = new JobBean() ;
        jobBean.setJobClass(MyJob.class.getName());
        jobBean.setJobName("MyJob1");
        jobBean.setCronExpression("0/2 * * * * ? *");
        JobUtils.createJob(scheduler , jobBean);
        return "job创建成功" ;
    }

    @GetMapping("pause")
    public String pauseJob(){
        JobUtils.pauseJob(scheduler , "MyJob1");
        return "job暂停成功" ;
    }
}
